<template>
  <!-- <a-card class="general-card" title="资产类型维护"> -->
  <div class="dashboard-container">
  

        <!-- 顶部统计卡片 -->
    <div class="stats-row">
      <div class="stat-card">
        <div class="stat-value">123</div>
        <div class="stat-label"><span class="stat-dot color-used"></span>已使用</div>
      </div>
      <div class="stat-card">
        <div class="stat-value">23</div>
        <div class="stat-label"><span class="stat-dot color-unused"></span>未使用</div>
      </div>
      <div class="stat-card">
        <div class="stat-value">0</div>
        <div class="stat-label"><span class="stat-dot color-alarm"></span>报警</div>
      </div>
      <div class="stat-card">
        <div class="stat-value">12</div>
        <div class="stat-label"><span class="stat-dot color-gateway"></span>网关</div>
      </div>
      <div class="stat-card">
        <div class="stat-value">5</div>
        <div class="stat-label"><span class="stat-dot color-room"></span>机房</div>
      </div>
    </div>

    <!-- 中间卡片和环形图 -->
    <div class="middle-row">
      
      <div class="info-card">
        <div class="info-left">
          <div class="info-item">
            <span class="icon-bg"><icon-nav /></span>
            <span class="info-label">网关数</span>
            <span class="info-value">3</span>
          </div>
          <div class="info-item">
            <span class="icon-bg"><icon-computer /></span>
            <span class="info-label">设备数</span>
            <span class="info-value">125</span>
          </div>
          <div class="info-item">
            <span class="icon-bg"><icon-apps /></span>
            <span class="info-label">机房数</span>
            <span class="info-value">63</span>
          </div>
        </div>
        <div class="info-center">
          <img src="/src/assets/images/home/center.jpg" alt="banner" />
        </div>
        <div class="info-right">
          <div class="room-title">机房状态：</div>
          <div class="room-list">
            <div
              v-for="(room, idx) in rooms"
              :key="room"
              class="room-tag"
            >
              <span
                class="room-dot"
                :class="roomDotColor(idx)"
              ></span>
              {{ room }}
            </div>
          </div>
        </div>
        <div class="info-footer">
          <span class="arrow"><icon-left /></span>
          <span class="footer-title">沙阳1号厂房</span>
          <span class="arrow"><icon-right /></span>
        </div>
        <div class="dots">
          <span v-for="i in 4" :key="i" :class="['dot', {active: i === 1}]"></span>
        </div>
      </div>



      <div class="pie-card">
        <v-chart :option="pieOption" autoresize style="height: 220px;" />
        <div class="pie-legend">
          <div v-for="item in pieLegend" :key="item.name" class="legend-item">
            <span :style="{background: item.color}" class="legend-dot"></span>
            <span>{{ item.name }}</span>
          </div>
        </div>
        <div class="pie-total">共：1657个设备</div>
      </div>
    </div>

    <!-- 下方柱状图和折线图 -->
    <div class="bottom-row">
      <div class="bar-card">
        <div class="chart-title">设备概览</div>
        <v-chart :option="barOption" autoresize style="height: 220px;" />
      </div>
      <div class="line-card">
        <div class="chart-title">报警数</div>
        <v-chart :option="lineOption" autoresize style="height: 220px;" />
      </div>
    </div>
  </div>
<!-- </a-card> -->
</template>

<script setup lang="ts">
import { ref } from 'vue'
import VChart from 'vue-echarts'

const rooms = [
  '1号机房', '12号机房', '21号机房', '4号机房',
  '11号机房', '6号机房', '5号机房', '17号机房',
]

const pieLegend = [
  { name: '机房', color: '#b266ff' },
  { name: '网关', color: '#ff7d4d' },
  { name: '小米电视', color: '#4d8aff' },
  { name: '打印机', color: '#ffd24d' },
  { name: '电脑', color: '#4dff88' },
  { name: '电脑机箱', color: '#433444' },
]

const pieOption = ref({
  tooltip: { trigger: 'item' },
  legend: { show: false },
  series: [
    {
      type: 'pie',
      radius: ['50%', '70%'],
      center: ['50%', '50%'],
      avoidLabelOverlap: false,
      label: {
        show: true,
        position: 'outside',
        formatter: '{b}\n{c}个',
      },
      labelLine: {
        show: true,
        length: 20,  // 第一段牵引线长度
        length2: 60, // 第二段牵引线长度
     
      },
      data: [
        { value: 500, name: '小米电视' },
        { value: 483, name: '电脑' },
        { value: 367, name: '电脑机箱' },
        { value: 102, name: '打印机' },
        { value: 16, name: '网关' },
        { value: 40, name: '机房' },
      ],
      color: pieLegend.map(i => i.color),
    },
  ],
})

const barOption = ref({
  tooltip: {},
  legend: { data: ['已使用', '未使用'] },
  xAxis: { data: ['电脑', '电视', '投影仪', '遥控器', 'xx设备'] },
  yAxis: {},
  series: [
    {
      name: '已使用',
      type: 'bar',
      data: [3200, 2100, 900, 1800, 700],
      itemStyle: { color: '#4d8aff' },
    },
    {
      name: '未使用',
      type: 'bar',
      data: [4200, 3100, 4700, 2300, 1700],
      itemStyle: { color: '#b266ff' },
    },
  ],
})

const lineOption = ref({
  tooltip: { trigger: 'axis' },
  xAxis: {
    type: 'category',
    data: [
      '2025/1/2', '2025/1/3', '2025/1/4', '2025/1/5',
      '2025/1/6', '2025/1/7', '2025/1/8', '2025/1/9',
    ],
  },
  yAxis: { type: 'value' },
  series: [
    {
      data: [0, 1, 2, 3.5, 1, 3, 2, 3.5],
      type: 'line',
      smooth: true,
      itemStyle: { color: '#4d8aff' },
    },
  ],
})

const roomDotColor = (idx: number) => {
  // 绿色：0,1,2,4,6，蓝色：3,5,7
  return [0,1,2,4,6].includes(idx) ? 'dot-green' : 'dot-blue'
}
</script>

<style scoped>
.dashboard-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 16px;
  overflow: hidden;
  width: 100%;
}
.stats-row {
  display: flex;
  gap: 24px;
}
.stat-card {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  padding: 24px 0 12px 0;
  text-align: center;
  box-shadow: 0 2px 8px #f0f1f2;
}
.stat-value {
  font-size: 30px;
  font-weight: bold;
}
.stat-label {
  color: #888;
  margin-top: 8px;
}
.stat-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.color-used { background: #3498ff; }      /* 蓝色 */
.color-unused { background: #a259ec; }    /* 紫色 */
.color-alarm { background: #ff4d4f; }     /* 红色 */
.color-gateway { background: #ff9900; }   /* 橙色 */
.color-room { background: #52c41a; }      /* 绿色 */
.middle-row {
  display: flex;
  gap: 24px;
}
.info-card {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  background: #fff;
  border-radius: 16px;
  padding: 24px ;
  box-shadow: 0 2px 8px #f0f1f2;
  position: relative;
  min-width: 600px;
}
.info-left,
.info-center,
.info-right {
  flex: 1;
  min-width: 0;
  padding: 0 5px;
  /* 这三块本身不用加省略号，加在内容元素上 */
}

.info-label,
.info-value,
.footer-title,
.room-tag {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  display: block;
}
.info-center img {
  max-width: 100%;
  height: auto;
  /* 图片自适应不溢出 */
}
.info-left {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.info-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(to right, #A3C6F7 0%, rgba(163,198,247,0) 100%), #fff;
  padding: 10px 10px;
  border-radius:16px ;

}
.icon-bg {
  width: 32px;
  height: 32px;
  background: #f5f6fa;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555555;
  font-size: 18px;
}
.info-label {
  color: #888;
  font-size: 15px;
}
.info-value {
  margin-left: auto;
  font-weight: bold;
  color: #222;
  font-size: 18px;
}
.info-center {
  display: flex;
  align-items: center;
  justify-content: center;
}
.info-center img {
  width: 180px;
  height: auto;
}
.info-right {
  margin-left: 0; /* 如果有 margin-left 记得去掉 */
}
.room-title {
  font-weight: bold;
  margin-bottom: 8px;
}
.room-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}
.room-tag {
  display: flex;
  align-items: center;
  font-size: 14px;
  background: none;
  color: #222;
  background: #EDEEF0;
  padding: 6px 4px;
  border-radius: 6px;
  
}
.room-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  display: inline-block;
}
.dot-green { background: #52c41a; }
.dot-blue { background: #4d8aff; }
.info-footer {
  position: absolute;
  left: 0; right: 0; bottom: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 15px;
  color: #888;
}
.dots {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 0;
  margin-top: 6px;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #eee;
  display: inline-block;
}
.dot.active {
  background: #222;
}
.pie-card {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.pie-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 0 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}
.pie-total {
  margin-top: 8px;
  color: #888;
  font-size: 14px;
}
.bottom-row {
  display: flex;
  gap: 24px;
}
.bar-card, .line-card {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
}
.chart-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
}
.arrow{
  cursor: pointer;
}
.middle-row > .info-card,
.middle-row > .pie-card {
  flex: 1;
  min-width: 0;
}
</style>
